using System;
using System.Collections.Generic;
using System.Text;

namespace BPMN.MainWindow
{
    public class ModuleEventStruct
    {
        public object sender;
        public FigureEvent figureEvent;
        public ModuleEventStruct(object sender, FigureEvent figureEvent)
        {
            this.sender = sender;
            this.figureEvent = figureEvent;
        }
    }
    public class EventManagement
    {
        Dictionary<FigureType, List<ModuleEventStruct>> registeredModulesEvents;
        static EventManagement uniqueInstance;

        private EventManagement()
        {
            registeredModulesEvents = new Dictionary<FigureType, List<ModuleEventStruct>>();
        }

        public static EventManagement GetInstance()
        {
            if (uniqueInstance == null)
            {
                uniqueInstance = new EventManagement();
                uniqueInstance.registeredModulesEvents.Add(FigureType.Pool, new List<ModuleEventStruct>());
                uniqueInstance.registeredModulesEvents.Add(FigureType.Lane, new List<ModuleEventStruct>());
            }
            return uniqueInstance;
        }

        public static void SendEventSignal(object sender, FigureUpdateEventArgs args)
        {
            foreach (ModuleEventStruct moduleEvent in EventManagement.uniqueInstance.registeredModulesEvents[args.FigureType])
            {
                if (moduleEvent.sender != sender)
                {
                    moduleEvent.figureEvent.Invoke(sender, args);
                }
            }
        }
        public void RegisterNewModule(FigureType figureType, ModuleEventStruct moduleEvent)
        {
            uniqueInstance.registeredModulesEvents[figureType].Add(moduleEvent);
        }
    }
}
